package client.authentication;

import static org.stjs.javascript.JSCollections.$array;

import org.stjs.javascript.Array;
import org.stjs.javascript.Window;

import vos.LoginCredentials;
import client.common.EndPoints.UserEP;
import client.common.angular.EmptyPromise;
import client.common.angular.NgScope;
import client.common.javascript.JsConsole;
import client.common.javascript.JsProcedure1;
import client.common.javascript.JsWindow;

public class AuthScope extends NgScope {

	public Array<String> roles;
	public LoginCredentials loginInfo;
	private UserEP userEP;
	private Window window;

	public AuthScope(UserEP user, JsWindow window) {
		super("AuthScope");
		this.userEP = user;
		this.window = window;

		roles = $array("COORDINADOR", "SECRETARIO", "PROFESOR", "ACUDIENTE");
		loginInfo = new LoginCredentials();

	}

	public static Array<String> $inject() {
		return $array("User", "$window");
	}

	public void suggestions(String query, JsProcedure1<Array<?>> callback) {
		Array<String> asd = $array();

		for (int i = 0; i < query.length(); i++) {
			asd.push(i + "asdasd");
		}

		callback.$invoke(asd);
	}

	public void doSomething(String asdasd) {
		JsConsole.console.log(asdasd);
	}

	public void logIn() {

		final AuthScope that = this;
		userEP.login(loginInfo, new JsProcedure1<EmptyPromise>() {
			@Override
			public void $invoke(EmptyPromise obj) {
				that.window.location.href = "/";
			}
		});

	}
}
